<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

Class UserRegister extends CWidget {

    public $httpReferer = '';

    public function run() {
	$model = new User;
	if (isset($_POST['ajax']) && $_POST['ajax'] === "register-form") {
	    echo CActiveForm::validate($model);
	    Yii::app()->end();
	}

	//when user register
	if (isset($_POST['signup'])) {
	    $model->attributes = $_POST['User'];
	    if ($model->validate()) {
		$activationKey = getRandomKey(20);
		$model->activation_key = $activationKey;
		if ($model->save()) {
		    //send mail	to active account
		    $receiptContent = array(
			'name' => $model->display_name,
			'activationKey' => $activationKey,
			'emailReceive' => $model->email
		    );
		    EmailHelper::sendMailResgistration($receiptContent);
		    $success = 1;
		}
	    }
	    $model->display_name = '';
	    $model->email = '';
	    $model->password = '';
	}

	$this->render('user_register', array('modelForm' => $model));
    }

}

